Skip to content

feat(py): reverse mode — port of interscript-rs src/reverse.rs (WO19 G10) - #857

Merged
ronaldtse merged 1 commit into
mainfrom
wo19-g10-ruby
Nov 14, 2026
Merged

ronaldtse merged 1 commit into
mainfrom
wo19-g10-ruby

Conversation

@ronaldtse

Copy link
Copy Markdown
Contributor

Summary

WO19 G10: reverse mode ported to the py engine (interscript-py/) — a choice-for-choice mirror of interscript-rs src/reverse.rs, whose expectations are ruby ground truth (Interscript::Node::*#reverse over interscript-ruby origin/main, spec'd by spec/reversibility_spec.rb).

  • src/interscript/reverse.py (new): stages reverse (children in reverse order, each rule reversed); sub rules swap from/to with boundary-like alias hoisting across the transfer and the capture/ref exchange; to upcase/to downcase swap via item case walks; funcalls invert through the Ruby Stdlib.reverse_function table; document name through Document.reverse_name; metadata swaps source/destination scripts; aliases/languages/dependencies pass through.
  • Compiled-IR deltas vs the rs node model (behavior identical, documented in the module docstring): no reverse_run in the IR — empty-reversed-from rules without assertions are dropped (ruby's own JSON-IR compilers omit them too); dependency recursion lives on the runtime entry point; capture groups are numbered by the regex engine in regex order (same numbers rs's assign_group_ids mints); priority negates per ruby Sub#reverse.
  • Runtime: Runtime.reverse reverses the dependency closure and serves the reversed docs under their forward names (rs reverse_document recursion); Runtime.load_map gains the ruby DSL.parse reverse-name load fallback (missing map whose reverse-named sibling exists loads that sibling reversed, cached under the requested code); MapLoader.register mirrors interscript-ts.
  • Stdlib: unseparate added (the reverse_function counterpart of separate); title_case corrected to ruby parity (upcase the first char and the char after each word separator — no lowering of the rest).
  • Documented ruby-crash deviations surface as named MapLogicErrors at reverse time (rs Error::Unsupported): repeat under a to upcase/downcase sub, a boundary hoist consuming the whole from group, a funcall outside the reverse_function map, an unhandled item kind in the transfer walk.

Ruby/rs untouched (they already have reverse). Mirror of the interscript-ts G10 PR.

Test plan

  • PYTHONPATH=src python3 -m pytest -q with GOLDEN_ROOT set — 450 collected, 0 failed (env-gated skips unchanged: 2 model-zip, 6 embedded-row)
  • 18 new reverse tests in tests/test_reverse.py incl. the real corpus map ALA-LC:bul-Cyrl:Latn:1997 (Kirillicata -> Кириллиcата) and all four documented-deviation error paths
  • python3 scripts/parse_parity_py.py --hand-rev 7a84260 — canonical 435/435, raw 435/435 (reverse adds no parse behavior)
  • Parity expectations ported 1:1 from interscript-rs tests/reverse.rs; fixtures vendored from tests/reverse_maps/ (plus rev-upcase-repeat for the repeat deviation)

…G10)

Mirror the rs reverse engine choice-for-choice at the compiled-IR
level: stages reverse (children in reverse order), sub rules swap
from/to with boundary-like alias hoisting across the transfer and the
capture/ref exchange, to upcase/downcase swap via item case walks,
funcalls invert through the Ruby Stdlib.reverse_function table, the
document name goes through Document.reverse_name, metadata swaps
source/destination scripts, aliases/languages/dependencies pass
through.

Runtime surface: Runtime.reverse reverses the dependency closure and
serves the reversed docs under their forward names (rs
reverse_document recursion); Runtime.load_map gains the ruby DSL.parse
reverse-name load fallback; MapLoader.register mirrors interscript-ts.
Stdlib: unseparate added (reverse_function counterpart of separate);
title_case corrected to ruby parity (upcase first char and the char
after each separator — no lowering).

Documented ruby-crash deviations surface as named MapLogicErrors at
reverse time (rs Error::Unsupported): repeat under a to-upcase/downcase
sub, a boundary hoist consuming the whole from group, a funcall
outside the reverse_function map, an unhandled item kind in the
transfer walk.

Gates: pytest 450 collected, 0 failed (GOLDEN_ROOT set); 18 new
reverse tests pass; py-vs-py parse parity driver canonical 435/435,
raw 435/435 (hand rev 7a84260) — reverse adds no parse behavior.
@ronaldtse
ronaldtse merged commit efb1936 into main Nov 14, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant